<template>
  <div>
    <el-dialog
      title="测试成绩编辑"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <el-form
        label-position="right"
        label-width="120px"
        :model="formLabelAlign"
      >
        <el-form-item label="项目名称：">
          <el-input v-model="formLabelAlign.name" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="测试结果：">
          <el-input v-model="formLabelAlign.result"></el-input>
        </el-form-item>
        <el-form-item label="测试成绩：">
          <el-input v-model="formLabelAlign.score"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from "vuex";
import axios from "axios";
export default {
  components: {},
  props: {
    formLabelAlign: {
      default: () => {
        return {
          name: "",
          result: "",
          score: "",
          num: 0,
        };
      },
    },
    dataId: {
      default: () => "",
    },
  },
  data() {
    return {
      dialogVisible: false,
    };
  },
  computed: {
    ...mapState({}),
  },
  watch: {},
  updated() {},
  beforeDestroy() {},
  created() {},
  methods: {
    handleClose() {
      this.dialogVisible = false;
      this.$message({
        type: "warning",
        message: "已取消编辑",
      });
    },
    openDialog() {
      this.dialogVisible = true;
    },
    submit() {
      console.log(this.formLabelAlign);
      let belonger = this.dataId;
      let type = this.formLabelAlign.name;
      let content = this.formLabelAlign.result;
      let teacherevaluate = this.formLabelAlign.score;
      console.log(belonger, type, content, teacherevaluate);
      axios
        .post("/api/user/updateUserScore", {
          content,
          teacherevaluate,
          belonger,
          type,
        })
        .then((res) => {
          console.log(res);
          this.dialogVisible = false;
          this.$message({ type: "success", message: "编辑成功" });
          axios
            .post("/api/user/showtablerecord", {})
            .then((response) => {
              var newArr = response.data.filter((item) => {
                if (this.dataId === item.belonger) {
                  return true;
                }
              });
              console.log(newArr);
              this.$emit("editScore", newArr);
              var num = 0;
              for (let i = 0; i < newArr.length; i++) {
                num += Number(newArr[i].teacherevaluate);
                this.num = num;
              }
              let score = this.num;
              console.log(score);
              let studentid = this.dataId;
              axios
                .post("/api/user/updateUserScoreAll", {
                  score,
                  studentid,
                })
                .then((res) => {
                  console.log(11111, res);
                });
              //console.log('姓名:  '+this.stus[0].name);
            })
            .catch((error) => {
              console.log(error);
            });
        });
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.el-button {
  position: static !important;
}
/deep/ .el-dialog {
  .el-dialog__header {
    background: #143853 !important;
  }
  .el-dialog__title {
    color: #ffffff;
  }
  .el-dialog__body {
    color: #ffffff;
    padding-bottom: 20px;
    background: #0f2d43 !important;
  }
  .el-dialog__footer {
    padding-right: 40px;
    background: #0f2d43;
  }
  .el-form-item__label {
    color: #ffffff;
  }
  .el-input__inner {
    background: #0355a4 !important;
    border: none;
    color: #ffffff;
  }
}
.main {
  display: flex;
}
</style>